package org.thread.test04.demo09;

/**
 * 第一：自定义线程类 - 必须继承Thread类
 * @author CSY
 * @date 2025 - 03 - 07
 */
public class MyThread extends Thread{
    private boolean flag = false;

    public void shutdown(){
        this.flag = true;
    }

    public MyThread() {}

    /**
     * 注意：在Thread中
     * @param name
     */
    public MyThread(String name) {
        super(name);
    }

    //重写run方法，实现线程的核心功能
    @Override
    public void run() {
        while(!flag) {
            System.out.println(Thread.currentThread().getName() + ":好好学习");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
